/** @format */
import { services, checkParams, noCheckUser, preCheck } from '../decorator/common';
import { resultsModel } from '../sdk';
import { UserService, AccessService,} from '../service';

export default class LoginController {

  /**
   *  登录接口, 初始化/更新用户信息
   */
  @checkParams(['activityId'])
  @noCheckUser
  @services([UserService, AccessService])
  async login(
    context: IContext<IParams>,
    { userInfo }: IControllerInfos,
    [userService, accessService]: [UserService, AccessService]
  ) {
    console.log(`login`, context, userInfo);

    const loginRes = await userService.doLogin(userInfo);
    const accessRes = await accessService.addAccess(loginRes);
    return resultsModel.success(accessRes);
  }

  /**
   *  获取用户信息
   */
  async getUserInfo(
    context: IContext<IParams>,
    { userInfo }: IControllerInfos,
  ) {
    return resultsModel.success({
      ...userInfo
    })
  }
}
